/**
 * TODO COSA FA ? COME SI USA?
 */
BootApplication.service('readerMenu', 
							 ['$http', '$q', 'configuration', 'log', 'windowManager','$rootScope','$location','$timeout',
	function readerMenuFactory($http,   $q,   config,          log,   windowManager,  $rootScope,  $location,  $timeout){
	

	 this.getMenuActive = function( _idUser ) {
		 var menu = $q.defer();
		 $http({
			 method: "GET",
			 url: config.getParam("Constants").ContextPath + "menuCtrl/getMenuActive.pjson",
			 params: {"idUser":_idUser}
		 }).then(function success(response){
    			menu.resolve(response.data);
		 });
		return menu.promise;
	 }
	 
	 this.getMenuPreferiti = function( _idUser) {
		 var menu = $q.defer();
		 $http({
			 method: "GET",
			 url: config.getParam("Constants").ContextPath + "menuCtrl/getMenuPreferiti.pjson",
			 params: {"idUser":_idUser}
		 }).then(function success(response){
    			menu.resolve(response.data);
		 });
		return menu.promise;
	 }
	 
	 this.saveMenuPreferito = function( newFiltriP, _idUser) {
		 _saveModel = {};
		 _saveModel.idUser 		= _idUser;
		 _saveModel.nome 		= "Preferito";
		 _saveModel.items 		= newFiltriP.items;
 		var _defer = $q.defer();
 		var request = {
 				  method	: 'POST'
 				  ,url		: config.getParam("Constants").ContextPath + "menuCtrl/saveMenuPreferito.pjson"
 				  ,data  	: _saveModel
 		};
   	  	$http(request).then(function(response){_defer.resolve(response);}, function(errorResponse){_defer.resolve(null);});
   	  	return _defer.promise;
	 }
	 
	 this.deleteMenuPreferito = function( _id, _idUser) {
		 _deleteModel = {};
		 _deleteModel.id 			= _id;
		 _deleteModel.idUser 		= _idUser;
//		 _deleteModel.items 		= [];
 		var _defer = $q.defer();
 		var request = {
 				  method	: 'POST'
 				  ,url		: config.getParam("Constants").ContextPath + "menuCtrl/deleteMenuPreferito.pjson"
 				  ,data  	: _deleteModel
 		};
   	  	$http(request).then(function(response){_defer.resolve(response);}, function(errorResponse){_defer.resolve(null);});
   	  	return _defer.promise;
	 }
	 
}]);
